//记分牌类
class Score {
  score: number = 0;
  level: number = 1;
  //分数和等级所在的元素， 在构造函数中进行初始化
  scoreEle: HTMLElement;
  levelEle: HTMLElement;
  //等级
  maxLevel: number;
  //升级的分数
  upscore: number;
  //maxLevel: number = 10 这里的10表示默认值
  constructor(maxLevel: number = 10, upscore: number = 10) {
    this.scoreEle = document.getElementById("score")!;
    this.levelEle = document.getElementById("level")!;
    this.maxLevel = maxLevel;
    this.upscore = upscore;
  }
  //设置一个加分的方法
  addScore() {
    // this.score++;
    this.scoreEle.innerHTML = ++this.score + "";
    //判断分数得多少
    if (this.score % this.upscore === 0) {
      this.levelUp();
    }
  }
  //等级提升
  levelUp() {
    //设置上限
    if (this.level < this.maxLevel) {
      this.levelEle.innerHTML = ++this.level + "";
    }
  }
}

export default Score;
